package day09API.stream;

import java.io.*;
import java.util.Scanner;

/**
 * @author DBX
 * @effect 记事本
 *          程序启动后，要求将控制台输入的每一行字符串都按行写入到文件note.txt
 *          当单独输入exit是退出程序
 *          要求：自行完成流连接
 * @date 2021/8/27 0027 - 15:22
 */
public class PWDemo3 {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos = new FileOutputStream("File/note.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);//相当于flush
        Scanner scanner = new Scanner(System.in);
        String str;
        do {
             str= scanner.nextLine();
             if ("exit".equals(str)){
                 break;
             }
             pw.println(str);
//             pw.flush();//这里可以不写 上构造方法中加true
        }while (true);
        pw.close();
    }
}
